
package harlequin;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

public class SectionEdit extends GeneralSection {


private String editquery = "Update section set courseSection = ?, professor = ? where courseSection = ?";
    
public SectionEdit(Connection connector, String tempDate, Integer setter) {
        
        this.setter = setter;
        this.connector = connector;
        this.tempDate = tempDate;
        this.setLocationByPlatform(rootPaneCheckingEnabled);
        this.setTitle("Edit Section");
        initComponents();
    }

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bEdit = new javax.swing.JButton();
        tProfessor = new javax.swing.JTextField();
        tIdSection = new javax.swing.JTextField();
        bBack = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        bEdit.setText("Edit");
        bEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bEditActionPerformed(evt);
            }
        });
        getContentPane().add(bEdit, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 250, 296, -1));
        getContentPane().add(tProfessor, new org.netbeans.lib.awtextra.AbsoluteConstraints(109, 42, 199, -1));

        tIdSection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tIdSectionActionPerformed(evt);
            }
        });
        getContentPane().add(tIdSection, new org.netbeans.lib.awtextra.AbsoluteConstraints(109, 13, 199, -1));

        bBack.setText("Back");
        bBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBackActionPerformed(evt);
            }
        });
        getContentPane().add(bBack, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 282, 296, -1));

        jLabel1.setText("Course-Section:");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 16, -1, -1));

        jLabel2.setText("Professor:");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 45, -1, -1));

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/HTGBG320320.jpg"))); // NOI18N
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 320, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void bEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bEditActionPerformed
        try {
            section = tIdSection.getText();
            professor = tProfessor.getText();

              if(section.isEmpty() && professor.isEmpty())
               JOptionPane.showMessageDialog(null, "Please input all empty fields.");
              //else if (SectionExsists(section))
               //JOptionPane.showMessageDialog(null, "Course with that Section already exsists");
              else if (section.isEmpty())
                JOptionPane.showMessageDialog(null, "Please indicate Section");
              else if (professor.isEmpty())
                JOptionPane.showMessageDialog(null, "Please indicate Professor of the Section");
              else {
              
 
            java.sql.PreparedStatement preparedStatement = connector.prepareStatement(editquery);
            preparedStatement.setString(1, section);
            preparedStatement.setString(2, professor);
            preparedStatement.setString(3, section);
            preparedStatement.executeUpdate();
            
            JOptionPane.showMessageDialog(null, "Edit Success!");
            this.dispose();
              }
            
        } catch (SQLException ex) {
            Logger.getLogger(ShowEdit.class.getName()).log(Level.SEVERE, null, ex);
        }
   
}//GEN-LAST:event_bEditActionPerformed

private void tIdSectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tIdSectionActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_tIdSectionActionPerformed

private void bBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBackActionPerformed
   this.dispose();

}//GEN-LAST:event_bBackActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bBack;
    private javax.swing.JButton bEdit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField tIdSection;
    private javax.swing.JTextField tProfessor;
    // End of variables declaration//GEN-END:variables
}
